
*set working directory
use "anes_mergedfile_1992to1997.dta", clear

* Panel ID
gen panel = 1992

* Case ID
gen id92 = VID92 
gen id96 = VID96
keep if id92 != . & id96 != .

* Weight
gen weight92 = V923009
gen weight96 = V960004
svyset[pweight=weight96]

***** PARTY ID *****

* Party identification
gen pid92 = V923634 - 3
replace pid92 = . if pid92 > 3
gen pid96 = V960420 - 3
replace pid96 = . if pid96 > 3

gen rep92 = 1 if pid92 > 1
replace rep92 = 0 if pid92 < -1
gen rep96 = 1 if pid96 > 1
replace rep96 = 0 if pid96 < -1

* Party ID strength
gen pidstrength92 = 3 if abs(pid92) == 3
replace pidstrength92 = 2 if abs(pid92) == 2
replace pidstrength92 = 1 if abs(pid92) == 1
replace pidstrength92 = 0 if abs(pid92) == 0

gen pidstrength96 = 3 if abs(pid96) == 3
replace pidstrength96 = 2 if abs(pid96) == 2
replace pidstrength96 = 1 if abs(pid96) == 1
replace pidstrength96 = 0 if abs(pid96) == 0

***** IDEOLOGY *****

* Ideology
gen ideo92 = V923509 - 4
replace ideo92 = . if abs(ideo92) > 3 
gen ideo96 = V960365 - 4
replace ideo96 = . if abs(ideo96) > 3 

gen conserv92 = 1 if ideo92 > 0
replace conserv92 = 0 if ideo92 < 0
gen conserv96 = 1 if ideo96 > 0
replace conserv96 = 0 if ideo96 < 0

* Ideological strength
gen ideostrength92 = 3 if abs(ideo92) == 3
replace ideostrength92 = 2 if abs(ideo92) == 2
replace ideostrength92 = 1 if abs(ideo92) == 1
replace ideostrength92 = 0 if abs(ideo92) == 0

gen ideostrength96 = 3 if abs(ideo96) == 3
replace ideostrength96 = 2 if abs(ideo96) == 2
replace ideostrength96 = 1 if abs(ideo96) == 1
replace ideostrength96 = 0 if abs(ideo96) == 0

***** PID-IDEO SORTING *****
replace ideostrength92 = ideostrength92 + 1
replace pidstrength92 = pidstrength92 + 1
gen sorting92 = abs(pid92 - (-1 * ideo92)) * ideostrength92 * pidstrength92

replace ideostrength96 = ideostrength96 + 1
replace pidstrength96 = pidstrength96 + 1
gen sorting96 = abs(pid96 - (-1 * ideo96)) * ideostrength96 * pidstrength96

***** DEMOGRAPHICS *****

* Education (ranges from 1-7)
gen edu92 = V923908
replace edu92 = . if edu92 >= 8
replace edu92 = . if edu92 < 1
label define edulab 1 "8 grades or less" 2 "9-12 grades" 3 "High school" ///
	4 "HS + non-academic training" 5 "Some college" 6 "BA" 7 "Advanced"
label values edu edulab

* Family income (1-24)
gen income92 = V924104
replace income92 = . if income > 24

* Race 
gen race92 = V924202
replace race92 = . if race92 == 9
gen white92 = 0
replace white92 = 1 if race92 == 1
gen black92 = 0
replace black92 = 1 if race92 == 2

* Gender (1=female)
gen female92 = V924201 - 1
replace female92 = . if female92 < 0
replace female92 = . if female92 > 1
label define genderlab 0 "Male" 1 "Female"
label values female92 genderlab

* Age (number of years) 
gen age92 = V923903
replace age92 = . if age92 > 91
replace age92 = . if age92 < 17

* Region
gen south92 = .
replace south92 = 0 
replace south92 = 1 if V923014 == 3
label define southern 0 "0 Non-South" 1 "1 South"
label values south southern

* Church attendance
gen church92 = V923821
replace church92 = . if church92 < 1
recode church92 (5=0) (4=1) (3=2) (2=3) (1=4)

gen church92_corrected = .
replace church92_corrected = 0 if V923820 == 5
replace church92_corrected = 1 if V923821 == 1
replace church92_corrected = 2 if V923821 == 2
replace church92_corrected = 3 if V923821 == 3
replace church92_corrected = church92_corrected/3

* Interest in campaigns 
gen interest92 = V925102
replace interest92 = . if interest92 > 5
replace interest92 = . if interest92 < 1
recode interest92 (1=3) (3=2) (5=1)
label define interestlab 1 "Not much interested" ///
	2 "Somewhat interested" 3 "Very much interested"
label values interest interestlab

***** AFFECTIVE POLARIZATION *****

* Party feeling thermometers
gen reptherm92 = V923318
replace reptherm92 = . if reptherm92 > 100
gen demtherm92 = V923317
replace demtherm92 = . if demtherm92 > 100
gen partydifftherm92 = abs(demtherm92 - reptherm92)

gen reptherm96 = V960293
replace reptherm96 = . if reptherm96 > 100
gen demtherm96 = V960292
replace demtherm96 = . if demtherm96 > 100
gen partydifftherm96 = abs(demtherm96 - reptherm96)

* Candidate feeling thermometers
gen rcandtherm92 = V923305
replace rcandtherm92 = . if rcandtherm92 > 100
gen dcandtherm92 = V923306
replace dcandtherm92 = . if dcandtherm92 > 100
gen diffcandtherm92 = abs(dcandtherm92 - rcandtherm92)

gen rcandtherm96 = V960273
replace rcandtherm96 = . if rcandtherm96 > 100
gen dcandtherm96 = V960272
replace dcandtherm96 = . if dcandtherm96 > 100
gen diffcandtherm96 = abs(dcandtherm96 - rcandtherm96)

* Ideological group feeling thermometers
gen contherm92 = V925319
replace contherm92 = . if contherm92 > 100
gen libtherm92 = V925326
replace libtherm92 = . if libtherm92 > 100
gen diffideotherm92 = abs(libtherm92 - contherm92)

gen contherm96 = V961031
replace contherm96 = . if contherm96 > 100
gen libtherm96 = V961032
replace libtherm96 = . if libtherm96 > 100
gen diffideotherm96 = abs(libtherm96 - contherm96)

***** ISSUE EXTREMITY *****

* Government spending and services
gen selfservice92 = V923701
replace selfservice92 = . if selfservice92 < 1
replace selfservice92 = . if selfservice92 >= 8
recode selfservice92 (1=3) (2=2) (3=1) (4=0) (5=-1) (6=-2) (7=-3)
label define servicelab -3 "Government should provide many more services" ///
	3 "Government should provide many fewer services"
label values selfservice92 servicelab

* Defense spending
gen selfdefense92 = V923707
replace selfdefense92 = . if selfdefense92 < 1
replace selfdefense92 = . if selfdefense92 >= 8
recode selfdefense92 (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label define defenselab -3 "Greatly decrease defense spending" ///
	3 "Greatly increase defense spending"
label values selfdefense92 defenselab

* Health insurance
gen selfinsure92 = V923716
replace selfinsure92 = . if selfinsure92 < 1
replace selfinsure92 = . if selfinsure92 > 7
recode selfinsure92 (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label define insurelab -3 "Government insurance plan" 3 "Private insurance plan"
label values selfinsure92 insurelab

* Guarenteed jobs
gen selfjobs92 = V923718
replace selfjobs92 = . if selfjobs92 < 1
replace selfjobs92 = . if selfjobs92 >= 8
recode selfjobs92 (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label define jobslab -3 "Government see to job and good standard of living" ///
	3 "Government let each person get ahead on his own"
label values selfjobs92 jobslab

* Aid to blacks
gen selfaid92 = V923724
replace selfaid92 = . if selfaid92 == 0
replace selfaid92 = . if selfaid92 >= 8
recode selfaid92 (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label define aidlab -3 "Government should help minority groups" ///
	3 "Minority groups should help themselves"
label values selfaid92 aidlab

* Issue extremity
gen issex1 = abs(selfdefense92 - 0)
gen issex2 = abs(selfservice92 - 0)	
gen issex3 = abs(selfaid92 - 0)	
gen issex4 = abs(selfinsure92 - 0)	
gen issex5 = abs(selfjobs92 - 0)	
alpha issex1-issex5, gen(issextreme92)
label var issextreme92 "Issue Extremity"

***** POLITICAL VALUES *****

* EGAL 1
gen equalopp92 = V926024 - 1
gen equalopp96 = V961229 - 1
replace equalopp92 = . if equalopp92 > 4
replace equalopp96 = . if equalopp96 > 4
label define equalopportunity 0 "0 Agree strongly" 1 "1 Agree somewhat" ///
	2 "2 Neither agree nor disagree" 3 "3 Disagree somewhat" ///
	4 "4 Disagree strongly"
label values equalopp92 equalopportunity
label values equalopp96 equalopportunity

* EGAL 2
gen equalrights92 = V926025
gen equalrights96 = V961230
replace equalrights92 = . if equalrights92 > 5
recode equalrights92 (5=0) (4=1) (3=2) (2=3) (1=4)
replace equalrights96 = . if equalrights96 > 5
recode equalrights96 (5=0) (4=1) (3=2) (2=3) (1=4)
label define equalrightspush 0 "0 Disagree strongly" 1 "1 Disagree somewhat" /// 
	2 "2 Neither agree nor disagree" 3 "3 Agree somewhat" 4 "4 Agree strongly"
label values equalrights92 equalrightspush
label values equalrights96 equalrightspush

* EGAL 3
gen equalchance92 = V926029 - 1
gen equalchance96 = V961231 - 1
replace equalchance92 = . if equalchance92 > 4
replace equalchance96 = . if equalchance96 > 4
label define equalchances 0 "0 Agree strongly" 1 "1 Agree somewhat" ///
	2 "2 Neither agree nor disagree" 3 "3 Disagree somewhat" ///
	4 "4 Disagree strongly"
label values equalchance92 equalchances
label values equalchance96 equalchances

* EGAL 4
gen lessequal92 = V926026
gen lessequal96 = V961232
replace lessequal92 = . if lessequal92 > 5
recode lessequal92 (5=0) (4=1) (3=2) (2=3) (1=4)
replace lessequal96 = . if lessequal96 > 5
recode lessequal96 (5=0) (4=1) (3=2) (2=3) (1=4)
label define lessequality 0 "0 Disagree strongly" 1 "1 Disagree somewhat" /// 
	2 "2 Neither agree nor disagree" 3 "3 Agree somewhat" 4 "4 Agree strongly"
label values lessequal92 lessequality
label values lessequal96 lessequality

* EGAL 5
gen unequal92 = V926027
gen unequal96 = V961233
replace unequal92 = . if unequal92 > 5
recode unequal92 (5=0) (4=1) (3=2) (2=3) (1=4)
replace unequal96 = . if unequal96 > 5
recode unequal96 (5=0) (4=1) (3=2) (2=3) (1=4)
label define unequalchance 0 "0 Disagree strongly" 1 "1 Disagree somewhat" ///
	2 "2 Neither agree nor disagree" 3 "3 Agree somewhat" 4 "4 Agree strongly"
label values unequal92 unequalchance
label values unequal96 unequalchance

* EGAL 6
gen fewer92 = V926028 - 1
gen fewer96 = V961234 - 1
replace fewer92 = . if fewer92 > 4
replace fewer96 = . if fewer96 > 4
label define fewerproblems04 0 "0 Agree strongly" 1 "1 Agree somewhat" ///
	2 "2 Neither agree nor disagree" 3 "3 Disagree somewhat" ///
	4 "4 Disagree strongly"
label values fewer92 fewerproblems04
label values fewer96 fewerproblems04

* MORAL 1
gen changing92 = V926115 - 1
gen changing96 = V961248 - 1
replace changing92 = . if changing92 > 4
replace changing96 = . if changing96 > 4
label define changingmorals 0 "Agree strongly" 1 "Agree somewhat" ///
	2 "Neither agree nor disagree" 3 "Disagree somewhat" 4 "Disagree strongly"
label values changing92 changingmorals
label values changing96 changingmorals
 
* MORAL 2
gen lifestyles92 = V926118
gen lifestyles96 = V961247
replace lifestyles92 = . if lifestyles92 > 5
recode lifestyles92 (5=0) (4=1) (3=2) (2=3) (1=4)
replace lifestyles96 = . if lifestyles96 > 5
recode lifestyles96 (5=0) (4=1) (3=2) (2=3) (1=4)
label define lifestylesnew 0 "0 Disagree strongly" 1 "1 Disagree somewhat" /// 
	2 "2 Neither agree nor disagree"  3 "3 Agree somewhat" 4 "4 Agree strongly"
label values lifestyles92 lifestylesnew
label values lifestyles96 lifestylesnew

* MORAL 3
gen standards92 = V926116 - 1
gen standards96 = V961250 - 1
replace standards92 = . if standards92 > 4
replace standards96 = . if standards96 > 4
label define standardsown 0 "0 Agree strongly" 1 "1 Agree somewhat" ///
	2 "2 Neither agree nor disagree" 3 "3 Disagree somewhat" ///
	4 "4 Disagree strongly"
label values standards92 standardsown
label values standards96 standardsown
 
* MORAL 4
gen family92 = V926117
gen family96 = V961249
replace family92 = . if family92 > 5
recode family92 (5=0) (4=1) (3=2) (2=3) (1=4)
replace family96 = . if family96 > 5
recode family96 (5=0) (4=1) (3=2) (2=3) (1=4)
label define familyties 0 "0 Disagree strongly" 1 "1 Disagree somewhat" /// 
	2 "2 Neither agree nor disagree"  3 "3 Agree somewhat" 4 "4 Agree strongly"
label values family92 familyties
label values family96 familyties

* Creating values scales
alpha equalopp92 equalrights92 equalchance92 lessequal92 unequal92 fewer92 ///
	changing92 lifestyles92 standards92 family92, detail item ///
	generate(valuescale92) 
alpha equalopp96 equalrights96 equalchance96 lessequal96 unequal96 fewer96 ///
	changing96 lifestyles96 standards96 family96, detail item ///
	generate(valuescale96) 

***** VALUE EXTREMITY *****

* Value polarization	
gen valuepold92 = .
gen valuepolr92 = .	
gen valuepold96 = .
gen valuepolr96 = .	
	
sum valuescale92 if valuescale92 != . & rep92 == 1, meanonly
replace valuepold92 = valuescale92 - r(mean) if valuescale92 != . & rep92 == 0
sum valuescale92 if valuescale92 != . & rep92 == 0, meanonly
replace valuepolr92 = valuescale92 - r(mean) if valuescale92 != . & rep92 == 1

sum valuescale96 if valuescale96 != . & rep96 == 1, meanonly
replace valuepold96 = valuescale96 - r(mean) if valuescale96 != . & rep96 == 0
sum valuescale96 if valuescale96 != . & rep96 == 0, meanonly
replace valuepolr96 = valuescale96 - r(mean) if valuescale96 != . & rep96 == 1

foreach v of var valuepold92 - valuepolr96{ 
	replace `v' = abs(`v')
}

egen valuepol92 = rowtotal(valuepold92 valuepolr92)
egen valuepol96 = rowtotal(valuepold96 valuepolr96)

***** SIX-ITEM VALUE SCALE (EQUIVALENT TO 2016-2020) *****
alpha equalopp92 lessequal92 unequal92 fewer92 ///
	changing92 family92, detail item ///
	generate(valuescale92_6item) 

alpha equalopp96 lessequal96 unequal96 fewer96 ///
	changing96 family96, detail item ///
	generate(valuescale96_6item) 

gen valuepold92_6item = .
gen valuepolr92_6item = .	
gen valuepold96_6item = .
gen valuepolr96_6item = .	
	
sum valuescale92_6item if valuescale92_6item != . & rep92 == 1, meanonly
replace valuepold92_6item = valuescale92_6item - r(mean) if valuescale92_6item != . & rep92 == 0
sum valuescale92_6item if valuescale92_6item != . & rep92 == 0, meanonly
replace valuepolr92_6item = valuescale92_6item - r(mean) if valuescale92_6item != . & rep92 == 1

sum valuescale96_6item if valuescale96_6item != . & rep96 == 1, meanonly
replace valuepold96_6item = valuescale96_6item - r(mean) if valuescale96_6item != . & rep96 == 0
sum valuescale96_6item if valuescale96_6item != . & rep96 == 0, meanonly
replace valuepolr96_6item = valuescale96_6item - r(mean) if valuescale96_6item != . & rep96 == 1

foreach v of var valuepold92_6item - valuepolr96_6item{ 
	replace `v' = abs(`v')
}

egen valuepol92_6item = rowtotal(valuepold92_6item valuepolr92_6item)
egen valuepol96_6item = rowtotal(valuepold96_6item valuepolr96_6item)


***** Subset to Necessary Variables and Save Coded Data *****
keep VVERSION VDSETNO VCASEID VICPSRNO VPARTIC V923908 V924104 V923903 V960004 panel-valuepol96_6item
save "anes_mergedfile_1992to1997_coded.dta", replace


***** Descriptive Statistics (Table 1) *****
	foreach var in valuepol92 valuepol92_6item partydifftherm92 diffcandtherm92 diffideotherm92 sorting92 issextreme92 interest92 edu92 age92 income92 church92_corrected female92 white92 black92 south92 {
		qui sum `var'
		replace `var' = (`var' - `r(min)') / (`r(max)'-`r(min)')

	}
	
sum valuepol92 valuepol92_6item partydifftherm92 diffcandtherm92 diffideotherm92 sorting92 issextreme92 interest92 church92_corrected female92 white92 black92 south92 [aweight=weight96], det
svy: tab V923908 if V923908 < 8 // cats 6 and 7 add up to 31% with a BA or higher
tabstat V924104 [aweight=weight96] if V924104 < 88, stats(n median) // cat 17 corresponds to $35,000-$39,999
tabstat V923903 [aweight=weight96], stats(n median) // median age is 37





